<?php
namespace service\login;

use encryption\Encryption;

class CpAction {
    /**
     * @desc 手机号修改密码
     * @param $params
     * @return array
     * @author zhaozhiwei
     * @date 2021-02-04 14:44
     */
    public static function main($params)
    {
        $user = \UserModel::getUserInfo($params['mobile']);
        if(empty($user)) return \Output2::fail(5001);//检测用户是否存在
        //检测验证码是否正确
        (new \cache\Redis())->set('login:login_code' . $params['mobile'], '123456');
        $code = (new \cache\Redis())->get('login:login_code' . $params['mobile']);
        if ($params['code'] !== $code) return \Output2::fail(5004);
        if ($user['status'] == 0) return \Output2::fail(5003);

        $pwd=Encryption::pwd_crype($params['password']);//新密码加密
        \UserModel::changePwdByMobile($params['mobile'],$pwd); //更新数据
        return \Output2::success();
    }
}